<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>分享转发中奖规则管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
	
	
	
	
		function seetingRuleType(){
			var ruleType = $('#rule_type_id').find('option:selected').text();
			$('#rule_name').val(ruleType);
			var ruleTypeVal =  $('#rule_type_id').val();
			if(ruleTypeVal == 3 || ruleTypeVal == 4 || ruleTypeVal == 5){
				$('#rule_data_id').removeClass('required');
				$('#rule_data_id').attr('placeholder',ruleType +'类型下不需要填数据.');
			}else{
				$('#rule_data_id').removeClass('required');
				$('#rule_data_id').addClass('required');
				$('#rule_data_id').attr('placeholder','输入规则数据...');
			}
		}
	
		$(document).ready(function() {
			var autoClear = '${shareRule.autoClear}';
			 if(autoClear =='') autoClear ="0";
			 $("input[name='autoClear'][value="+autoClear+"]").attr("checked","checked");  
			 
			 
			$("#name").focus();
			seetingRuleType();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
		
		
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/wechat/share/shareRule/">分享转发中奖规则列表</a></li>
		<li class="active"><a href="${ctx}/wechat/share/shareRule/form?id=${shareRule.id}">分享转发中奖规则<shiro:hasPermission name="wechat:share:shareRule:edit">${not empty shareRule.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="wechat:share:shareRule:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="shareRule" action="${ctx}/wechat/share/shareRule/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<form:hidden path="user.id"/>
		<form:hidden path="name" id="rule_name"/>
		
		<tags:message content="${message}"/>
		<div class="control-group">
			<label class="control-label">规则类型:</label>
			<div class="controls">
				<form:select id="rule_type_id" path="type" onchange="seetingRuleType();">
					<form:options items="${ruleTypeList }" itemLabel="value" itemValue="key" />
				</form:select>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">奖品名称:</label>
			<div class="controls">
				<form:textarea path="awardName"  htmlEscape="false" cols="10" rows="3"  placeholder="请输入奖品名称" class="required" />
			</div>
		</div>
		
		
		<div class="control-group">
			<label class="control-label">自动核销:</label>
			<div class="controls">
				<input type="radio" name="autoClear"  value="1"> 是 &nbsp;&nbsp;&nbsp;<input type="radio" name="autoClear" value="0"> 否  <span class="alert" style="margin-left:150px">中奖及时核销,用于纯添加积分奖品.</span>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">增加积分:</label>
			<div class="controls">
				<form:input path="score" id="scoreId" htmlEscape="false" maxlength="11" class="required digits"  />  <span class="alert">请填写0-1000之间的数字,中奖后直接增加该积分.</span>
			</div>
		</div>
		
		
		
		<div class="control-group">
			<label class="control-label">规则数据:</label>
			<div class="controls">
				<form:textarea path="rule" id="rule_data_id" htmlEscape="false" cols="10" rows="3" class="required"/>  <span class="alert">请输入与规则匹配的数字，如果是多个，用','英文状态下的逗号隔开。如 1,100,1000,10000</span>
			</div>
		</div>
		
		
		
		<div class="control-group">
			<label class="control-label">备注:</label>
			<div class="controls">
				<form:input path="remarks" htmlEscape="false" maxlength="50" placeholder="可不填"/>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="wechat:share:shareRule:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>
